package com.web.dao;

import com.web.entity.Menu;
import com.web.entity.Role;
import com.web.entity.SysMenu;
import com.web.utils.mybatis.SimpleSelectInLangDriver;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;
import java.util.Map;

/**
 * @author FDjavaone
 */
public interface MenuMapper {


    @Delete({
            "delete from t_menu",
            " where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
            "insert into t_menu (store_id, title,",
            " create_time, modify_time)",
            " values (#{storeId,jdbcType=BIGINT}, #{title,jdbcType=VARCHAR}, ",
            " #{createTime,jdbcType=TIMESTAMP}, #{modifyTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insert(Menu record);

    @InsertProvider(type = MenuSqlProvider.class, method = "insertSelective")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insertSelective(Menu record);


    @Select({
            "select",
            " id, store_id, title, create_time, modify_time",
            " from t_menu",
            " where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "store_id", property = "storeId", jdbcType = JdbcType.BIGINT),
            @Result(column = "title", property = "title", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    Menu selectByPrimaryKey(Long id);

    @UpdateProvider(type = MenuSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Menu record);

    @Update({
            "update t_menu",
            " set store_id = #{storeId,jdbcType=BIGINT},",
            " title = #{title,jdbcType=VARCHAR},",
            " create_time = #{createTime,jdbcType=TIMESTAMP},",
            " modify_time = #{modifyTime,jdbcType=TIMESTAMP}",
            " where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Menu record);

    @Select({
            "select",
            " id, store_id, title, create_time, modify_time",
            " from t_menu",
            " where store_id = #{id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "store_id", property = "storeId", jdbcType = JdbcType.BIGINT),
            @Result(column = "title", property = "title", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    List<Menu> selectByStoreId(Long id);


    @Select("select * from t_sys_menu where id in(#{ids})")
    @Lang(SimpleSelectInLangDriver.class)
    List<SysMenu> selectInId(@Param("ids") List<Long> ids);

    @Select("select store_id from t_menu where id in(#{ids}) ")
    @Lang(SimpleSelectInLangDriver.class)
    List<Long> selectStoreIdByMenuId(@Param("ids") List<Long> ids);
}